package com.jesse.flow;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import java.io.IOException;

public class FlowMapper  extends Mapper<LongWritable,Text, Text,FlowBean> {
    private Text outK =   new Text();
    private FlowBean outV =   new FlowBean();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //1.获取和一行信息
        String line = value.toString();

        //2.切割
        String[] split = line.split("\t");

        //3.抓取数据
        String phoneno = split[1];
        String upflow = split[split.length-3];
        String downflow = split[split.length-2];

        //4.封装
        outK.set(phoneno);
        outV.setUpFlow(Long.parseLong(upflow));
        outV.setDownFlow(Long.parseLong(downflow));
        outV.setSumFlow();

        //5.写出
        context.write(outK,outV);
    }
}